package com.lancoo.answer.ui.child.original;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.lancoo.answer.R;
import com.lancoo.answer.model.AnswerConstant;
import com.lancoo.answer.model.ConstantBean;
import com.lancoo.answer.model.bean.Child;
import com.lancoo.answer.model.bean.ExamViewBean;
import com.lancoo.answer.model.bean.Ques;
import com.lancoo.answer.model.bean.Type;
import com.lancoo.answer.widget.combinationView.FillAnswerResultView;
import com.lancoo.answer.widget.combinationView.QueseBodyView;

import java.util.List;


/**
 * Created by pengmi on 2021/12/1 20:53
 * Description:词汇填空，句子填空，翻译填空，改写句子，短文填空，单词填空，词汇替换题型查看评阅小题fragment
 */
public class ChildFillOriginalFragment extends Fragment {

    private QueseBodyView tv_queseBody;
    private FillAnswerResultView fillAnswerResultView;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.ev_fragment_child_fill_look_review, container, false);
    }

    public static Fragment loadChildFragment(int kindIndex, int queseIndex, int smallQueseIndex){
        ChildFillOriginalFragment queseFragment=new ChildFillOriginalFragment();
        Bundle mBundle=new Bundle();
        mBundle.putInt(AnswerConstant.KEY_TYPEINDEX,kindIndex);
        mBundle.putInt(AnswerConstant.KEY_QUESINDEX,queseIndex);
        mBundle.putInt(AnswerConstant.KEY_CHILDINDEX,smallQueseIndex);
        queseFragment.setArguments(mBundle);
        return queseFragment;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
    }

    private void initView(View view){
        if(getArguments()==null){
            return;
        }
        int typeIndex=getArguments().getInt(AnswerConstant.KEY_TYPEINDEX);
        int queseIndex=getArguments().getInt(AnswerConstant.KEY_QUESINDEX);
        int childIndex=getArguments().getInt(AnswerConstant.KEY_CHILDINDEX);
        ExamViewBean constantExamBean = ConstantBean.Companion.getConstantExamBean();
        if(constantExamBean==null){
            return;
        }
        List<Type> typeList = constantExamBean.getTypeList();
        if(typeList==null||typeList.size()<=typeIndex){
            return;
        }
        Type type = typeList.get(typeIndex);
        List<Ques> quesList = type.getQuesList();
        if(quesList==null||quesList.size()<=queseIndex){
            return;
        }
        Ques ques = quesList.get(queseIndex);
        List<Child> childList = ques.getChildList();
        if(childList==null||childList.size()<=childIndex){
            return;
        }
        Child child =childList.get(childIndex);
        tv_queseBody = view.findViewById(R.id.quese_body_view);
        tv_queseBody.setShowType(2);
        tv_queseBody.initData(child);
        fillAnswerResultView=view.findViewById(R.id.fill_answer_result);
        fillAnswerResultView.setHideScore(true);
        fillAnswerResultView.setFillResult(child,ques.getGenreID());
    }


    @Override
    public void onPause() {
        super.onPause();
        if(tv_queseBody!=null){
            tv_queseBody.pause();
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if(tv_queseBody!=null){
            tv_queseBody.release();
        }
    }


    public void adjustFontSize(){
        if(tv_queseBody!=null){
            tv_queseBody.adjustFontSize();
            fillAnswerResultView.adjustFontSize();
        }
    }
}
